package payroll.trans;

import payroll.Employee;

import payroll.PaymentClassification;

import payroll.PayrollDatabase;

import payroll.TimeCard;

import payroll.Transaction;

import payroll.classification.HourlyClassification;

import payroll.exception.NoSuchEmployeeException;

import payroll.exception.NotHourlyClassificationException;

public class TimeCardTransaction implements Transaction {

	   private int empId;
	   private String date;
	   private double hours;

	public TimeCardTransaction(int empId, String date, double hours) {
		this.empId = empId;
		this.date = date;
		this.hours = hours;
	}

	@Override
	public void execute() {
		Employee e = PayrollDatabase.getEmployee(empId);
		if (e != null) {
			PaymentClassification pc = e.getPaymentClassification();
			if (pc instanceof HourlyClassification) {
				HourlyClassification hc = (HourlyClassification) pc;
				hc.addTimeCard(new TimeCard(date, hours));
			} else {
				throw new NotHourlyClassificationException();
			}
		} else {
			throw new NoSuchEmployeeException();
		}
	}

}